<? include ("../init.php") ?>
<?
  $news_id = $_POST['news_id'];
  
  $detail = addslashes($_POST['detail']);
  $date = strtotime($_POST['date']);
  $title = addslashes($_POST['title']);
  $img_sql = '';

  
  if(isset($_FILES["news_img"]) && is_uploaded_file($_FILES["news_img"]["tmp_name"]) && $_FILES["news_img"]["tmp_name"]!=''){
    $handle = new Upload($_FILES['news_img']);
    if ($handle->uploaded)
    {
      $handle->image_resize = true;
      $handle->image_ratio_fill = true;
      $handle->image_x = 220;
      $handle->image_y = 160;
      $handle->Process(APPPATH.'/images/news/'.$news_id);
      
      if ($handle->processed)
      {
        $img_sql = 'news_img="'.$handle->file_dst_name.'",';
      }
    }
    
    $sql = "UPDATE hs_news SET $img_sql news_date='$date',news_detail='$detail',news_title='$title' WHERE news_id=$news_id";
    if(!mysql_query($sql))
    {
      @unlink(APPPATH.'/images/news/'.$news_id.'/'.$handle->file_dst_name);
    }
    else
    {
      if(trim($_POST['old_img'])!='' AND file_exists(APPPATH.'/images/news/'.$news_id.'/'.$_POST['old_img'])){
        @unlink(APPPATH.'/images/news/'.$news_id.'/'.$_POST['old_img']);
      }
    }
  }else{
    $sql = "UPDATE hs_news SET news_date='$date',news_detail='$detail',news_title='$title' WHERE news_id=$news_id";
    mysql_query($sql);
  }
  
  
  
  header("Location:index.php");
?>